import { ref } from 'vue'
import { defineStore } from 'pinia'
import { getCurrentUserUsingGet1 } from '@/api/yonghumokuaijiekou'

/**
 * 存储登录用户信息的状态
 */
export const useLoginUserStore = defineStore('loginUser', () => {
  // 用户信息
  const loginUser = ref<API.LoginUserVO>({
    id: null,
    userName: '',
    userAccount: '',
    userAvatar: '',
    userRole: '',
    createTime: '',
    updateTime: '',
    isForbid: '',
    userProfile: '',
  })

  // 设置用户信息
  const setLoginUser = (user: API.LoginUserVO) => {
    loginUser.value = user
  }

  // 获取登录用户信息
  const fetchLoginUser = async () => {
    const res = await getCurrentUserUsingGet1({})
    if (res.data.code === 200) {
      loginUser.value = res.data.data
    }
  }

  // 返回
  return {
    loginUser,
    fetchLoginUser,
    setLoginUser,
  }
})
